<extend name="Layout/ins_page" />
<block name="content">
	{:W('PageHeader/simple',array('name'=>'修改密码'))}
	<div class="sub-frame gray">
		<form id="form_password" method="post" action="">
			<input type="hidden" name="ajax" id="ajax" value="1">
			<div class="layui-form-item">
				<label class="layui-form-label" for="password">新密码：</label>
				<div class="layui-input-block">
					<input class="layui-input col-20" type="password" name="password" id="password" value=""  >
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label" for="list_rows">确认密码：</label>
				<div class="layui-input-block">
					<input class="layui-input col-20" type="password" name="confirm_password" id="confirm_password" value=""  >
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<span id="msg"></span>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<a id="btn_save"  class="btn">保存</a>
				</div>
			</div>
		</form>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global'], function() {
			var $ = layui.jquery;
			

			function check_password(s) {
				if (s.length < 4) {
					return 0;
				}
				var ls = 0;
				if (s.match(/[a-z]/ig)) {
					ls++;
				}
				if (s.match(/[0-9]/ig)) {
					ls++;
				}
				if (s.match(/(.[^a-z0-9])/ig)) {
					ls++;
				}
				if (s.length < 6 && ls > 0) {
					ls--;
				}
				return ls;
			};

			$("#password").keydown(function() {
				s = $(this).val();
				t = check_password(s);
				if (t == 0) {
					$("#msg").html("密码过短");
					$("#msg").css("color", "red");
				}
				if (t == 1) {
					$("#msg").html("密码强度差");
					$("#msg").css("color", "red");
				}
				if (t == 2) {
					$("#msg").html("密码强度良好");
					$("#msg").css("color", "blue");
				}
				if (t == 3) {
					$("#msg").html("密码强度高");
					$("#msg").css("color", "blue");
				}
			});

			$("#confirm_password").keyup(function() {
				new_pwd = $("#password").val();
				confirm_pwd = $(this).val();
				if (new_pwd != confirm_pwd) {
					$("#msg").html("密码不一致");
					$("#msg").css("color", "red");
				} else {
					$("#msg").html("密码一致");
					$("#msg").css("color", "blue");
					$("#status").val("true");
				}
			});

			$("#btn_save").on('click', function() {
				var msg = "";
				var vars = $("#form_password").serialize();
				new_pwd = $("#password").val();
				confirm_pwd = $("#confirm_password").val();
				if (new_pwd == confirm_pwd) {
					send_ajax("{:U('reset_pwd')}", vars, function(data) {
						layer.msg(data.info);
					});
				} else {
					layer.msg("密码不一致");
				}
			});
		});

	</script>
</block>